package qe.spider.grab;

import cn.hutool.core.text.UnicodeUtil;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import qe.spider.vo.Stock;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


//同花顺问财-最近5个交易日有过涨停或跌停
@Slf4j
public class GrabWenCaiByWebDriver {

    private WebDriver web;

    public GrabWenCaiByWebDriver() {
        String chromePath = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
        System.setProperty("webdriver.edge.bin", chromePath);
        String driverPath = "d:\\msedgedriver.exe";
        System.setProperty("webdriver.edge.driver",driverPath);
        web = new EdgeDriver();
    }

    public static void main(String[] args) throws IOException {
        GrabWenCaiByWebDriver driver = new GrabWenCaiByWebDriver();
        driver.drive("000919,603949,000705");
    }

    public void drive(List<Stock> stocks) {
        drive(stocks.stream().map(Stock::getStock_code).collect(Collectors.joining(",")));
    }

    public void drive(String stocks) {
        String url = "https://www.iwencai.com/unifiedwap/result?w=" + stocks + "%E6%9C%80%E8%BF%915%E4%B8%AA%E4%BA%A4%E6%98%93%E6%97%A5%E6%9C%89%E8%BF%87%E6%B6%A8%E5%81%9C%E6%88%96%E8%B7%8C%E5%81%9C%E5%90%97&querytype=stock";
        url = "http://127.0.0.1:8888/app/goods/";
        web.get(url);
        web.getTitle();
        String ret = web.getPageSource();
    }


}
